package com.yx.crawler.runtime;

import com.yx.crawler.typedef.CrawlerUrl;

public class CrawlerQueuePolicy {
	private CrawlerQueue breadthFirst;
	private CrawlerQueue depthFirst;
	public CrawlerQueuePolicy(CrawlerQueue breadthFirst,CrawlerQueue depthFirst) {
		this.breadthFirst=breadthFirst;
		this.depthFirst=depthFirst;
	}
	public void putBreadthFirst(CrawlerUrl crawlerUrl)throws Exception{
		breadthFirst.push(crawlerUrl);
	}
	public void putDepthFirst(CrawlerUrl crawlerUrl)throws Exception{
		depthFirst.push(crawlerUrl);
	}
	protected boolean copyBreadthBasedIntoDepthBased(){
		try{
			CrawlerUrl crawlerUrl= breadthFirst.pop();
			if(crawlerUrl==null)return false;
			depthFirst.push(crawlerUrl);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	protected CrawlerUrl popDepthFirst(){
		if(depthFirst.length()<1)return null;
		try{
			return depthFirst.pop();
		}catch(Exception e){
			return null;
		}
	}
	public int breadthFirstLenght(){
		return breadthFirst.length();
	}
	public int depthFirstLenght(){
		return depthFirst.length();
	}
}
